package group5_邱义成;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ZuoYE {
    public static void main(String[] args) {
        int a=0;
        while (true) {
            System.out.println("【-----------------------------欢迎来到作业检查系统--------------------------】");
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入需要检查的文件路径，如：F:\\信本一班作业");
            String path1 = scanner.next();
            System.out.println("请输入对比名单，如：F:\\作业.txt");
            String path2 = scanner.next();
            System.out.println("请输入未交作业名单的打印路径，如：F:\\未交作业.txt");
            String path3 = scanner.next();
            BufferedReader bufferedReader = null;
            BufferedWriter bufferedWriter = null;
            List<String> list = new ArrayList<String>();
            try {
                bufferedReader = new BufferedReader(new FileReader(path2));
                bufferedWriter = new BufferedWriter(new FileWriter(path3));
                File file = new File(path1);
                File[] files = file.listFiles();
                String str = null;
                String tem = null;
                for (File file1 : files) {
                    String file2 = file1.getName();
                    Matcher matcher = Pattern.compile("1班(\\d+)").matcher("" +
                            file2);
                    while (matcher.find()) {
                        tem = matcher.group(1);
                    }
                    list.add(tem);
                }
           /*for (String list1:list){
               System.out.println(list1);
           }*/
                while ((str = bufferedReader.readLine()) != null) {
                    boolean bool = list.contains(str);
                    if (bool == false) {
                        bufferedWriter.write(str);
                        bufferedWriter.write("           ");
                    }
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    bufferedReader.close();
                    bufferedWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("--------检查完成退出请按1,继续请按其他数字----------");
            if ((a=scanner.nextInt())==1) {
                break;
            }
        }
    }
}
